/**
 * @file bsp_led.h
 * @brief LED driver for H743-V2 Flight Control System
 * @author Flight Control Team
 * @date 2025-10-31
 */

#ifndef __BSP_LED_H
#define __BSP_LED_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdbool.h>

/**
 * @brief LED identifiers
 */
typedef enum {
    LED_GREEN = 0,  // PE2 - System status
    LED_RED   = 1,  // PE3 - Error indicator
    LED_BLUE  = 2,  // PE4 - Activity indicator
    LED_COUNT = 3
} LED_t;

/**
 * @brief LED state
 */
typedef enum {
    LED_STATE_OFF = 0,
    LED_STATE_ON  = 1,
    LED_STATE_TOGGLE = 2
} LEDState_t;

/**
 * @brief LED pattern for blinking
 */
typedef struct {
    uint16_t on_time_ms;
    uint16_t off_time_ms;
    uint16_t repeat_count;  // 0 = infinite
} LEDPattern_t;

/**
 * @brief Initialize LED GPIO
 * @return 0 on success, -1 on error
 */
int BSP_LED_Init(void);

/**
 * @brief Turn on LED
 * @param led LED identifier
 */
void BSP_LED_On(LED_t led);

/**
 * @brief Turn off LED
 * @param led LED identifier
 */
void BSP_LED_Off(LED_t led);

/**
 * @brief Toggle LED
 * @param led LED identifier
 */
void BSP_LED_Toggle(LED_t led);

/**
 * @brief Set LED state
 * @param led LED identifier
 * @param state LED state (0=off, 1=on)
 */
void BSP_LED_Set(LED_t led, bool state);

/**
 * @brief Get LED state
 * @param led LED identifier
 * @return true if LED is on, false if off
 */
bool BSP_LED_GetState(LED_t led);

/**
 * @brief Set LED pattern (for blinking)
 * @param led LED identifier
 * @param pattern LED pattern
 */
void BSP_LED_SetPattern(LED_t led, const LEDPattern_t *pattern);

/**
 * @brief Update LED patterns (call periodically)
 */
void BSP_LED_Update(void);

/**
 * @brief Turn off all LEDs
 */
void BSP_LED_AllOff(void);

/**
 * @brief Turn on all LEDs
 */
void BSP_LED_AllOn(void);

/**
 * @brief LED test sequence
 */
void BSP_LED_Test(void);

#ifdef __cplusplus
}
#endif

#endif /* __BSP_LED_H */

